<?php
/**
 * Created by PhpStorm.
 * User: wjj
 * Date: 2016/11/1
 */

namespace app\logic;

use app\models\Banner;
use app\models\History;
use app\models\Message;

class CommonLogic
{
    public function getArea($parent_code,$level){
        //return Area::find()->where(['parent_code'=>$parent_code,'region_level'=>$level])->asArray()->all();
    }

    public function getBanners($banner_type){
        return Banner::find()->where(['banner_type'=>$banner_type,'is_del'=>0])->asArray()->all();
    }

    public function addHistory($user_id,$id,$type,$pic,$state){
        if($history = History::findOne(['user_id'=>$user_id,'id'=>$id,'type'=>$type])){
            $history->state = $state;
            $history->time = date('Y-m-d H:i:s');
        }else{
            $history = new History();
            $history->user_id = $user_id;
            $history->id = $id;
            $history->type = $type;
            $history->pic = $pic;
            $history->state = $state;
            $history->time = date('Y-m-d H:i:s');
        }
        $history->save();
    }

    public function getMessage(){
        return Message::find()->asArray()->all();
    }

}